<template>
	<view class="content" :style="app_bg">
		<view class="topTitle" style="left: -30rpx;" :style="'top:'+zhuangtai+'px'">
			<view class="" style="font-size: 32rpx;">
				任务中心
			</view>
		</view>
		<view class="user" :style="user_margin_top">
			<view class="userinfo">
				<image class="avatar" :src="avatar" mode=""></image>
				<view class="userindexa">
					<view class="font30 nameclass" :style="font_1st">{{nickname}}</view>
					<view class="userother">
						<view class="item" :style="app_bg">
							<image :src="appConfig.gold_coin_icon" mode=""></image>
							<text class="font22 item-icon-number" :style="font_3rd">{{appConfig.gold_coin_name}}：{{member_gold_coin}}</text>
						</view>
						<view class="item" style="margin-left: 44rpx;" :style="app_bg">
							<image :src="appConfig.game_coin_icon" mode=""></image>
							<text class="font22 item-icon-number" :style="font_3rd">{{appConfig.game_coin_name}}：{{member_game_coin}}</text>
						</view>
						<view class="item" style="margin-top: 10rpx;" :style="app_bg">
							<image :src="appConfig.exp_icon" mode=""></image>
							<text class="font22 item-icon-number" :style="font_3rd">{{appConfig.exp_name}}：{{member_exp}}</text>
						</view>
						<view class="item" style="margin-top: 10rpx;margin-left: 44rpx;" :style="app_bg">
							<image :src="appConfig.money_icon" mode=""></image>
							<text class="font22 item-icon-number" :style="font_3rd">{{appConfig.money_name}}：{{member_money}}</text>
						</view>
					</view>
				</view>
			</view>
			<view class="exchangebtn" @click="goTexchange">
				<image class="bgimgpublic index-0" :src="taskimg.btn_xs_warm" mode=""></image>
				<text class="font30 index-1" :style="font_1st">兑换</text>
			</view>
		</view>
		<view class="Sign" :style="app_theme">
			<view class="font34 fontw500 titletext" :style="font_1st">签到中心</view>
			<view class="signindex" :style="app_border_top">
				<scroll-view :scroll-x="true" class="money"  style="box-sizing: border-box;padding: 0 30rpx 0 22rpx;">
					<view class="flexaaa">
						<view class="miniItem" v-for="(item, index) in signList" :key="index">
							<image class="bgimgpublic index-0" :src="taskimg.sign_bg_image" mode=""></image>
							<image class="topbg" :src="taskimg.sign_reward_bg_image" mode=""></image>
							<image class="itemicon" v-if="item.is_reward_money == 1" :src="appConfig.money_icon" mode=""></image>
							<image class="itemicon" v-else-if="item.is_reward_gold_coin == 1" :src="appConfig.gold_coin_icon" mode=""></image>
							<image class="itemicon" v-else-if="item.is_reward_game_coin == 1" :src="appConfig.game_coin_icon" mode=""></image>
							<image class="itemicon" v-else :src="appConfig.exp_icon" mode=""></image>
							<image class="signready" v-if="item.days<=sign_days" :src="taskimg.sign_complete_btn" mode=""></image>
							<view class="itemtext" :style="font_3rd">
								<image class="bgimgpublic" :src="taskimg.sign_reward_content_bg_image" mode=""></image>
								<text class="font28" v-if="item.is_reward_money == 1">{{appConfig.money_name}}X{{item.reward_money}}</text>
								<text class="font28" v-if="item.is_reward_gold_coin == 1">{{appConfig.gold_coin_name}}X{{item.reward_gold_coin}}</text>
								<text class="font28" v-if="item.is_reward_game_coin == 1">{{appConfig.game_coin_name}}X{{item.reward_game_coin}}</text>
								<text class="font28" v-if="item.is_reward_exp == 1">{{appConfig.exp_name}}X{{item.reward_exp}}</text>
							</view>
							<view class="font28" :style="'z-index:2;color:'+publicTextColor.font_1st_color+';'">
								第{{item.days}}天
							</view>
						</view>
					</view>
				</scroll-view>
			</view>
			<view v-if="today_is_sign == 0" class="doublesignbtn margin0auto" @click="signFirst(1)">
				<image class="bgimgpublic index-0" :src="taskimg.sign_btn" mode=""></image>
				<text class="font34 index-1" :style="font_1st">双倍签到</text>
			</view>
			<!-- signClick -->
			<view class="font30 ordinary" @click="signFirst(0)" v-if="today_is_sign == 0" :style="font_3rd">普通签到</view>
			<view class="font30 ordinary ready-sign" v-if="today_is_sign == 1" :style="font_1st">
				<image class="bgimgpublic index-0" :src="taskimg.btn_xs_disabled" mode=""></image>
				<text class="index-1">已签到</text>
			</view>
			<view class="signother" :style="app_border_top">
				<view class="font30" @click="goToSignRule" :style="font_3rd">签到规则</view>
				<view class="time">
					<view class="font30" :style="font_3rd">签到提醒</view>
					<switch style="transform: scale(0.7);" color="#2EC56A" :checked="isChecked" @change="switchChange" />
				</view>
			</view>
		</view>
		<view class="tasktitle">
			<scroll-view :scroll-x="true" class="money"  style="">
				<view class="" style="display: -webkit-box;">
					<view class="titleitem" @click="changetitle(item.id)" v-for="(item, index) in category" :key="index">
						<view class=""
							:style="item.id == tasktitleId ? (font_1st+';font-size:34rpx'):(font_3rd+';font-size:30rpx')">{{item.name}}</view>
						<view class="little" v-if="item.is_finish == 1"></view>
					</view>
				</view>
			</scroll-view>
		</view>
		<view class="taskinfo" :style="app_theme">
			<block v-for="(item, index) in taskList" :key="index">
				<view class="item" :style="app_border_bottom">
					<view class="iteminfo">
						<image class="invitationicon" :src="item.image" mode=""></image>
						<view class="itemtext">
							<view class="text1 font30" :style="font_1st">{{item.name}}</view>
							<view class="reward" v-if="item.is_reward_money == 1">
								<image :src="appConfig.money_icon" mode=""></image>
								<text class="font28" :style="font_3rd">{{appConfig.money_name}}{{item.reward_money_min}}~{{item.reward_money_max}}</text>
							</view>
							<view class="reward" v-if="item.is_reward_gold_coin == 1">
								<image :src="appConfig.gold_coin_icon" mode=""></image>
								<text class="font28" :style="font_3rd">{{appConfig.gold_coin_name}}{{item.reward_gold_coin_min}}~{{item.reward_gold_coin_max}}</text>
							</view>
							<view class="reward" v-if="item.is_reward_game_coin == 1">
								<image :src="appConfig.game_coin_icon" mode=""></image>
								<text class="font28" :style="font_3rd">{{appConfig.game_coin_name}}{{item.reward_game_coin_min}}~{{item.reward_game_coin_max}}</text>
							</view>
							<view class="reward" v-if="item.is_reward_exp == 1">
								<image :src="appConfig.exp_icon" mode=""></image>
								<text class="font28" :style="font_3rd">{{appConfig.exp_name}}：{{item.reward_exp_min}}~{{item.reward_exp_max}}</text>
							</view>
							<view class="reward" v-if="item.is_card == 1">
								<image :src="item.image" mode=""></image>
								<text class="font28" :style="font_3rd">卡片{{item.card_amount_min}}~{{item.card_amount_max}}</text>
							</view>
							<view class="reward" v-if="item.is_super_card == 1">
								<image :src="appConfig.super_card_icon" mode=""></image>
								<text class="font28" :style="font_3rd">万能卡{{item.super_card_min}}~{{item.super_card_max}}</text>
							</view>
						</view>
					</view>
					<view class="btn" v-if="item.member_task_status == 1 && item.cd_second<=0" @click="taskcompleteClick(item,index) ">
						<image class="bgimgpublic index-0" :src="taskimg.btn_xs_warm" mode=""></image>
						<text class="font30 index-1" :style="font_1st">领取</text>
					</view>
					<view class="btn" v-if="item.cd_second>0">
						<text class="font30 index-1" :style="font_1st">{{item.cd_second}}</text>
					</view>
					<view class="btn" @click="taskLookAdVideo(item.ad_unit,item.ad_type,item.id,item.ad_click,item.ad_type)" v-if="item.member_task_status == 0 && item.type !=2 && item.cd_second<=0 ">
						<image class="bgimgpublic index-1" :src="taskimg.btn_xs_disabled" mode=""></image>
						<text class="font30 index-1" :style="font_1st">
							<text v-if="item.type == 1">{{item.member_task_going}}/{{item.sign_day}}</text>
							<text v-if="item.type == 3">{{item.member_task_going}}/{{item.level}}</text> 
							<text v-if="item.type == 4">{{item.member_task_going}}/{{item.ad_amount}}</text> 
							<text v-if="item.type == 5">{{item.member_task_going}}/{{item.answer_times}}</text> 
							<text v-if="item.type == 6">{{item.member_task_going}}/{{item.card_combine}}</text> 
						</text>
					</view>
					<button class="btn" type='default' open-type="share" v-if="item.member_task_status == 0 && item.type ==2 && item.cd_second<=0">
						<image class="bgimgpublic index-1" :src="taskimg.btn_xs_disabled" mode=""></image>
						<text class="font30 index-1" :style="font_1st">
							<text v-if="item.type == 2">{{item.member_task_going}}/{{item.invite_member_amount}}</text> 
						</text>
					</button>
					<view class="btn" v-if="item.member_task_status == 2 && item.cd_second<=0">
						<image class="bgimgpublic" :src="taskimg.btn_xs_primary" mode=""></image>
						<text class="font30 index-1" :style="font_1st">已完成</text>
					</view>
				</view>
			</block>
		</view>
		<uni-popup ref="signsuccess" type="center">
			<view class="filesynpopup">
				<view class="filetop" :style="'background:'+publicTextColor.app_border_color+';'">
					<image :src="taskimg.btn_close" mode="" @click="closeSignPopup"></image>
					<text class="font30" :style="font_1st">提示</text>
				</view>
				<view class="filecenter" :style="app_theme">
					<view class="signsuccessimg">
						<image class="bgimgpublic index-0" style="z-index: 0;" :src="taskimg.sign_success_bg_image" mode=""></image>
						<image class="signgoods" v-if="sign_reward.reward_exp!=0" :src="appConfig.exp_icon" mode="aspectFit"></image>
						<image class="signgoods" v-else-if="sign_reward.reward_game_coin!=0" :src="appConfig.game_coin_icon" mode="aspectFit"></image>
						<image class="signgoods" v-else-if="sign_reward.reward_gold_coin!=0" :src="appConfig.gold_coin_icon" mode="aspectFit"></image>
						<image class="signgoods" v-else="sign_reward.reward_money!=0" :src="appConfig.money_icon" mode="aspectFit"></image>
					</view>
					<text class="tiptext font30" :style="font_1st">恭喜您签到成功，成功领取
						<text v-if="sign_reward.reward_exp!=0" :style="font_2nd">{{appConfig.exp_name}}*{{sign_reward.reward_exp}}</text>
						<text v-if="sign_reward.reward_game_coin!=0" :style="font_2nd">{{appConfig.game_coin_name}}*{{sign_reward.reward_game_coin}}</text>
						<text v-if="sign_reward.reward_gold_coin!=0" :style="font_2nd">{{appConfig.gold_coin_name}}*{{sign_reward.reward_gold_coin}}</text>
						<text v-if="sign_reward.reward_money!=0" :style="font_2nd">{{appConfig.money_name}}*{{sign_reward.reward_money}}</text>
						坚持签到领取更多好礼哦~
					</text>
					<view class="btn" @click="closeSignPopup">
						<image class="bgimgpublic" :src="taskimg.btn_xs_warm" mode=""></image>
						<text class="font30 index-1" :style="font_1st">确定</text>
					</view>
				</view>
			</view>
		</uni-popup>
		<uni-popup ref="taskcomplete" type="center">
			<view class="successsynpopup">
				<view class="successtop">
					<image class="bgimgpublic" :src="taskimg.alert_success_image_1" mode=""></image>
					<text class="font48 fontw" 
						:style="'margin-top:-19rpx;'+font_1st"
					>
						恭喜您
					</text>
				</view>
				<view class="successcenter">
					<view class="goodsimg">
						<image class="bgimg" :src="taskimg.index_live_comment_bg_image_1" mode=""></image>
						<view class="successgoods">
							<image v-if="completeFinish.is_card == 1" class="bgimgpublic" :src="appConfig.card_image" mode=""></image>
							<image v-else-if="completeFinish.is_reward_exp == 1" class="bgimgpublic" :src="completeFinish.exp_image" mode=""></image>
							<image v-else-if="completeFinish.is_reward_game_coin == 1" class="bgimgpublic" :src="appConfig.game_coin_image" mode=""></image>
							<image v-else-if="completeFinish.is_reward_gold_coin == 1" class="bgimgpublic" :src="appConfig.gold_coin_image" mode=""></image>
							<image v-else-if="completeFinish.is_reward_money == 1" class="bgimgpublic" :src="appConfig.money_image" mode=""></image>
							<image v-else-if="completeFinish.is_super_card == 1" class="bgimgpublic" :src="appConfig.super_card_image" mode=""></image>
						</view>
					</view>
					<text class="successtext font36" :style="font_1st">恭喜您完成任务获得
						<text v-if="completeFinish.is_card == 1" :style="font_2nd">{{completeFinish.card_name}}*{{completeFinish.card_amount}} </text>
						<text v-if="completeFinish.is_reward_exp == 1" :style="font_2nd">{{appConfig.exp_name}}*{{completeFinish.exp}} </text>
						<text v-if="completeFinish.is_reward_game_coin == 1" :style="font_2nd">{{appConfig.game_coin_name}}*{{completeFinish.game_coin}} </text>
						<text v-if="completeFinish.is_reward_gold_coin == 1" :style="font_2nd">{{appConfig.gold_coin_name}}*{{completeFinish.gold_coin}} </text>
						<text v-if="completeFinish.is_reward_money == 1" :style="font_2nd">{{appConfig.money_name}}*{{completeFinish.money}} </text>
						<text v-if="completeFinish.is_super_card == 1" :style="font_2nd">万能卡*{{completeFinish.super_card_amount}} </text>
						~
					</text>
				</view>
				<view class="successbtn" @click="$refs.taskcomplete.close()">
					<image class="bgimgpublic" :src="taskimg.btn_sm_warm" mode=""></image>
					<text class="font36" :style="font_1st">我知道了</text>
				</view>
			</view>
		</uni-popup>
		<uni-popup ref="cardAd" type="center">
			<view class="showcardclass">
				<image @click="$refs.cardAd.close()" class="closeimage" :src="taskimg.banner_btn_close" mode=""></image>
				<view class="cardinfo">
					<image class="adimage" src="../../static/adpopup1.png" mode=""></image>
					<view class="text1 font36 fontw"></view>
				</view>
				<!-- #ifdef MP-WEIXIN -->
				<view v-if="cardadid != '' && ad_type == 3 " class="" style="display: flex;justify-content: center; margin:0 auto; width: 680rpx;">
					<ad v-if="cardadid != ''" :unit-id="cardadid" ad-type="video"></ad>
				</view>
				<view v-if="cardadid != '' && ad_type == 2 " class="" style="display: flex;justify-content: center;margin:0 auto; width: 680rpx;">
					<ad v-if="cardadid != ''" :unit-id="cardadid" ad-type="banner"></ad>
				</view>
				<!-- #endif -->
			</view>
		</uni-popup>
		<view class="footTabList" :style="'background:'+publicTextColor.app_theme_color+';'+(is_iphone?'padding-bottom:40rpx;':'padding-bottom:10rpx;')">
			<view class="listitem" @click="goToTab(item.url,item.url_name)" v-for="(item, index) in menu" :key="index">
				<image :src="item.name=='任务'?item.icon_selected : item.icon" mode=""></image>
				<view :style="item.name=='任务'? 'color:'+item.font_color_selected:'color:'+item.font_color">{{item.name}}</view>
			</view>
		</view>
	</view>
</template>

<script>
	var util = require('@/js/util.js')
	export default {
		data() {
			return {
				publicTextColor:'',
				pubilcPopupImg:'',
				taskimg:'',
				zhuangtai:0,
				signopen:true,
				tasktitleId:"",
				sign_days:0,
				is_iphone:false,
				menu:[],
				nickname:"",
				avatar:"",
				taskList:[],
				category:[],
				//签到-------
				signList:[],//签到列表
				sign_rules:'',//签到规则
				isChecked:false,//签到提醒是否打开
				today_is_sign:0,//今天是否签到
				sign_condition:0,//是否有签到前置条件
				rewarded_ad_unit:"",//签到激励视频id
				openVideo:null,//激励视频配置
				sign_condition_rewarded_video_amount:0,//前置条件 看视频次数
				sign_condition_invite_amount:0,//前置条件 邀请人数
				member_invite_total:0,//前置条件 用户邀请人数
				member_ad_total:0,//前置条件 用户看视频次数
				member_sign_condition:0,//用户是否已达到前置条件 1已达到 0未达到
				sign_notice_template_id:"",//签到订阅id
				is_rewarded_video_ad:0,//签到是否翻倍
				sign_reward:'',
				//签到结束-------------
				ad_unit:"",
				task_id:"",
				taskItem:"",
				ad_click:"",
				is_ad_click:false,
				cdTaskList:[],
				taskIndex:'',
				showTaskCd:[],
				taskCd:[],
				cardadid:'',
				ad_type:0,
				clickcardad:false,
				isclickcardad:false,
				appConfig:'',
				member_gold_coin:0,
				member_game_coin:0,
				member_money:0,
				member_exp:0,
				completeFinish:'',
				adVideoType:0,
				is_count_down:0
			};
		},
		onLoad() {
			this.setcolorConfig()
		},
		created() {
			uni.hideTabBar()
		},
		computed:{
			user_margin_top(){
				return `margin-top:${(this.zhuangtai+52)}px;background:${this.publicTextColor.app_theme_color};'`
			},
			app_border_top(){
				return `border-top:2rpx solid ${this.publicTextColor.app_border_color};`
			},
			app_border_bottom(){
				return `border-bottom:2rpx solid ${this.publicTextColor.app_border_color};`
			},
			app_theme(){
				return `background:${this.publicTextColor.app_theme_color};`
			},
			app_bg(){
				return `background:${this.publicTextColor.app_bg_color};`
			},
			font_3rd(){
				return `color:${this.publicTextColor.font_3rd_color};`
			},
			font_2nd(){
				return `color:${this.publicTextColor.font_2nd_color};`
			},
			font_1st(){
				return `color:${this.publicTextColor.font_1st_color};`
			}
		},
		onShareAppMessage() { // 分享 buttom share
			return {
				title: '合成王者',
				path: '/pages/index/index?parent_id='+uni.getStorageSync('member_id')
			}
		},
		onHide() {
			for(let key in this.cdTaskList){
				console.log()
				clearInterval(this.cdTaskList[key])
			}
			if(this.ad_click == 1){
				this.is_ad_click = true
			}
			if(this.isclickcardad){
				this.clickcardad = true
			}
		},
		onShow() {
			console.log(uni.getStorageSync("token"))
			this.loadtaskIndex()
			this.getSignIndex()
			this.menu = uni.getStorageSync("menu")
			if(this.clickcardad){
				this.postTaskVideo()
			}
			let that = this
			let aniosgaodu = 0
			uni.getSystemInfo({
				success: function(res) {
					console.log(res);
					that.zhuangtai = res.statusBarHeight;
					var a = res.model.split(' ');
					if (a[0] == 'iPhone') {
						aniosgaodu = 44;
						that.is_iphone = true
					} else {
						aniosgaodu = 48;
					}
					that.zhuangtai = parseInt(that.zhuangtai)+4
					console.log(that.zhuangtai)
				}
			});
		},
		methods:{
			signFirst(type){
				let _self = this
				if(_self.sign_condition == 1){
					if(_self.member_sign_condition == 1){
						_self.isSubscribe(type)
					}else{
						var signdesc = `需要完成看视频${_self.sign_condition_rewarded_video_amount-_self.member_ad_total}次,邀请${_self.sign_condition_invite_amount-_self.member_invite_total}`
						uni.showModal({
							title:'提示',
							content:signdesc,
							confirmText:"看视频",
							success: (res) => {
								if(res.confirm){
									_self.lookAdVideo(_self.rewarded_ad_unit,2)
								}
							}
						})
					}
				}else{
					_self.isSubscribe(type)
				}
			},
			isSubscribe(type){
				let _self = this
				var thatlist = [_self.sign_notice_template_id];
				console.log("1",thatlist)
				//微信消息订阅
				wx.requestSubscribeMessage({
					tmplIds:thatlist,
					success(res){
						console.log(res)
						if(res[thatlist] === 'accept'){
							_self.beforeSign(type)
							_self.isChecked = true
						}else if(res[thatlist] === 'reject'){
							_self.beforeSign(type)
							_self.isChecked = false
						}
					},
					fail:(err)=>{
						console.log(err)
					}
				})	
			},
			beforeSign(type){
				let _self = this
				uni.request({
					url: util.getUrl("sign/subscribe_message"),
					header: {
						'content-type': 'application/x-www-form-urlencoded',
						'Authori-zation':uni.getStorageSync("token")
					},
					data:{
					},
					method: 'POST',
					success: res => {
						if(res.data.code == 1){
							if(type == 1){
								_self.lookAdVideo(_self.rewarded_ad_unit,1)
							}else{
								_self.signClick()
							}
						}
					},
				});
			},
			getSignIndex(){
				let _self = this
				uni.request({
					url: util.getUrl("sign/index"),
					header: {
						'content-type': 'application/x-www-form-urlencoded',
						'Authori-zation':uni.getStorageSync("token")
					},
					data:{
					},
					method: 'POST',
					success: res => {
						if(res.data.code == 1){
							_self.signList = res.data.data.sign
							_self.sign_rules = res.data.data.sign_rules
							_self.today_is_sign = res.data.data.today_is_sign
							_self.sign_days = res.data.data.sign_days
							_self.rewarded_ad_unit = res.data.data.rewarded_ad_unit
							_self.sign_condition_rewarded_video_amount = res.data.data.sign_condition_rewarded_video_amount
							_self.sign_condition_invite_amount = res.data.data.sign_condition_invite_amount
							_self.sign_condition = res.data.data.sign_condition
							_self.member_money = res.data.data.member_money
							_self.member_exp = res.data.data.member_exp
							_self.member_gold_coin = res.data.data.member_gold_coin
							_self.member_game_coin = res.data.data.member_game_coin 
							_self.member_invite_total = res.data.data.member_invite_total
							_self.member_ad_total = res.data.data.member_ad_total
							_self.member_sign_condition = res.data.data.member_sign_condition
							_self.sign_notice_template_id = res.data.data.sign_notice_template_id
							if(res.data.data.sign_notice == 1){
								_self.isChecked = true
							}else{
								_self.isChecked = false
							}
							
						}
					},
				});
			},
			signLookAdVideo(){
				let _self = this
				uni.request({
					url: util.getUrl("sign/reward_ad"),
					header: {
						'content-type': 'application/x-www-form-urlencoded',
						'Authori-zation':uni.getStorageSync("token")
					},
					data:{
					},
					method: 'POST',
					success: res => {
						_self.adVideoType = 0
						if(res.data.code == 1){
							uni.showToast({
								title:'视频观看成功',
								icon:'success'
							})
						}
					},
				});
			},
			loadtaskIndex(){
				let _self = this
				uni.request({
					url: util.getUrl("task/index"),
					header: {
						'content-type': 'application/x-www-form-urlencoded',
						'Authori-zation':uni.getStorageSync("token")
					},
					data:{
					},
					method: 'POST',
					success: res => {
						if(res.data.code == 1){
							_self.nickname = res.data.data.nickname
							_self.avatar = res.data.data.avatar
							_self.taskList = res.data.data.list
							_self.category = res.data.data.category
							_self.tasktitleId = _self.category[0].id
							_self.member_money = res.data.data.member_money
							_self.member_exp = res.data.data.member_exp
							_self.member_gold_coin = res.data.data.member_gold_coin
							_self.member_game_coin = res.data.data.member_game_coin 
							console.log(_self.category[0].id,_self.tasktitleId)
							for(let key in _self.taskList){
								if(_self.taskList[key].cd_second>0){
									_self.taskCd_second(key)
								}
							}
						}else if(res.data.code == 500){
							uni.showToast({
								title:res.data.msg,
								icon:'none'
							})
							uni.navigateTo({
								url:'../login/login'
							})
							
						}
					},
				});
			},
			updateloadtaskIndex(){
				for(let key in this.cdTaskList){
					clearInterval(this.cdTaskList[key])
				}
				let _self = this
				uni.request({
					url: util.getUrl("task/index"),
					header: {
						'content-type': 'application/x-www-form-urlencoded',
						'Authori-zation':uni.getStorageSync("token")
					},
					data:{
						category_id:_self.tasktitleId
					},
					method: 'POST',
					success: res => {
						if(res.data.code == 1){
							_self.taskList = res.data.data.list
							_self.member_money = res.data.data.member_money
							_self.member_exp = res.data.data.member_exp
							_self.member_gold_coin = res.data.data.member_gold_coin
							_self.member_game_coin = res.data.data.member_game_coin 
							for(let key in _self.taskList){
								if(_self.taskList[key].cd_second >0){
									_self.taskCd_second(key)
								}
							}
						}else if(res.data.code == 500){
							uni.showToast({
								title:res.data.msg,
								icon:'none'
							})
							uni.navigateTo({
								url:'../login/login'
							})
						}
					},
				});
			},
			taskLookAdVideo(ad_unit,type,task_id,ad_click,ad_type){
				this.task_id = task_id
				this.ad_click = ad_click
				if(type == 1){
					this.lookAdVideo(ad_unit,3)
				}else{
					this.ad_type = ad_type
					this.cardadid = ad_unit
					this.isclickcardad = true
					this.$refs.cardAd.open()
					if(this.ad_click !=1){
						this.postTaskVideo()
					}
				}
			},
			lookAdVideo(adUnitId,type){
				let _self = this
				_self.adVideoType = type
				if(_self.openVideo == null){
					_self.openVideo = uni.createRewardedVideoAd({
						adUnitId:adUnitId,
					})
					_self.openVideo.load((resLoad)=>{
						console.log("adload",resLoad)
					})
					_self.openVideo.onError(function(eError){
						console.log("eError",eError)
					})
					_self.openVideo.onClose((res)=>{
						console.log(type,"type")
						if(res && res.isEnded){
							if(_self.adVideoType == 1){
								_self.is_rewarded_video_ad = 1
								_self.signClick()
								_self.adVideoType = 0
							}
							if(_self.adVideoType == 2){
								_self.signLookAdVideo()
								_self.adVideoType = 0
							}
							if(_self.adVideoType == 3){
								if(_self.ad_click == 1 ){
									if(_self.is_ad_click){
										_self.postTaskVideo()
									}else{
										uni.showToast({
											title:"未点击视频下方链接，观看失败！",
											icon:'none'
										})
										_self.is_ad_click = false
									}
								}else{
									_self.postTaskVideo()
								}
								_self.adVideoType = 0
							}
						}
					})
				}
				uni.showModal({
					title: '提示',
					content: '观看视频以继续' ,
					success: function (res) {
						if (res.confirm) {
							console.log('用户点击确定');
							_self.openVideo.show()
								.catch(() => {
									_self.openVideo.load()
										.then(() => {
											_self.openVideo.show()
										})
										.catch(err => {
											console.log('激励视频 广告显示失败')
											_self.active = false
											uni.showToast({
												title: '暂无激励视频',
												icon: 'none',
												duration: 2000
											});
										})
								})
							// ^视频显示
						} else if (res.cancel) {
							console.log('用户点击取消');
						}
					}
				});
			},
			postTaskVideo(){
				let _self = this
				uni.request({
					url: util.getUrl("task/reward_ad"),
					header: {
						'content-type': 'application/x-www-form-urlencoded',
						'Authori-zation':uni.getStorageSync("token")
					},
					data:{
						task_id:_self.task_id
					},
					method: 'POST',
					success: res => {
						_self.adVideoType = 0
						if(res.data.code == 1){
							uni.showToast({
								title:'观看成功!',
								icon:'success'
							})
							_self.isclickcardad = false
							_self.clickcardad = false
							_self.updateloadtaskIndex()
						}else if(res.data.code == 500){
							uni.showToast({
								title:res.data.msg,
								icon:'none'
							})
							uni.navigateTo({
								url:'../login/login'
							})
						}
					},
				});
			},
			goTexchange(){
				uni.navigateTo({
					url:'../../synthesis/other/exchangeShop'
				})
			},
			goToSignRule(){
				uni.navigateTo({
					url:'../../synthesis/other/signRule'
				})
			},
			taskcompleteClick(item,index){
				let _self = this
				_self.taskItem = item
				_self.taskIndex = index
				uni.request({
					url: util.getUrl("task/finish"),
					header: {
						'content-type': 'application/x-www-form-urlencoded',
						'Authori-zation':uni.getStorageSync("token")
					},
					data:{
						task_id:item.id
					},
					method: 'POST',
					success: res => {
						if(res.data.code == 1){
							_self.is_count_down = res.data.data.reward.is_count_down
							_self.completeFinish = res.data.data.reward
							_self.$refs.taskcomplete.open()
							_self.updateloadtaskIndex()
						}else{
							if(res.data.code == 500){
								uni.navigateTo({
									url:'../login/login'
								})
							}
							uni.showToast({
								title:res.data.msg,
								icon:'none'
							})
						}
					}
				});
			},
			closeSignPopup(){
				this.$refs.signsuccess.close()
			},
			taskCd_second(index){
				this.cdTaskList[index] = setInterval(()=>{
					this.taskList[index].cd_second -- 
					if(this.taskList[index].cd_second<=0){
						clearInterval(this.cdTaskList[index])
					}
				},1000)
			},
			signClick(){
				console.log("signClick")
				let _self = this
				uni.request({
					url: util.getUrl("sign/in"),
					header: {
						'content-type': 'application/x-www-form-urlencoded',
						'Authori-zation':uni.getStorageSync("token")
					},
					data:{
						is_rewarded_video_ad:_self.is_rewarded_video_ad
					},
					method: 'POST',
					success: res => {
						_self.adVideoType = 0
						if(res.data.code == 1){
							_self.sign_reward = res.data.data.sign_reward
							_self.$refs.signsuccess.open()
							_self.is_rewarded_video_ad = 0
							_self.getSignIndex()
						}else{
							uni.showToast({
								title:res.data.msg,
								icon:'none'
							})
						}
					}
				});
			},
			changetitle(id){
				this.tasktitleId = id
				// this.taskList = []
				this.updateloadtaskIndex()
			},
			switchChangisSubscribe(){
				let _self = this
				uni.request({
					url: util.getUrl("sign/notice"),
					header: {
						'content-type': 'application/x-www-form-urlencoded',
						'Authori-zation':uni.getStorageSync("token")
					},
					data:{
					},
					method: 'POST',
					success: res => {
						if(res.data.code == 1){
							
						}else{
							if(res.data.code == 500){
								uni.navigateTo({
									url:'../login/login'
								})
							}
							uni.showToast({
								title:res.data.msg,
								icon:'none'
							})
						}
					}
				});
			},
			switchChange(e){
				let _self = this
				_self.isChecked = e.detail.value
				var thatlist = [_self.sign_notice_template_id];
				if(_self.isChecked){
					wx.requestSubscribeMessage({
						tmplIds:thatlist,
						success(res){
							console.log(res)
							if(res[thatlist] === 'accept'){
								_self.isChecked = true
								_self.switchChangisSubscribe()
							}else if(res[thatlist] === 'reject'){
								_self.isChecked = false
							}
						},
						fail:(err)=>{
							console.log(err)
						}
					})	
				}else{
					_self.switchChangisSubscribe()
				}
			},
			setcolorConfig(){
				this.publicTextColor = uni.getStorageSync("diyColor")
				this.taskimg = uni.getStorageSync("diyImg")
				this.appConfig = uni.getStorageSync("appconfig")
			},
			goToTab(url,url_name){
				console.log(url)
				if(url_name == "首页"){
					uni.reLaunch({
						url:'../../synthesis/other/index'
					})
				}else if(url_name == "任务"){
					
				}else if(url_name == '我的'){
					uni.reLaunch({
						url:'../../pages/my/index'
					})
				}
			}
		}
	}
</script>

<style lang="scss">
	.showcardclass{
		display: flex;
		align-items: center;
		flex-direction: column;
		width: 690rpx;
		position: relative;
		.closeimage{
			height: 60rpx;
			width: 60rpx;
			top: -80rpx;
			right: 0;
			position: absolute;
		}
		.cardinfo{
			background: #FFFFFF;
			border-radius: 20rpx;
			box-sizing: border-box;
			margin-bottom: 30rpx;
			margin-top: 21rpx;
			.text1{
				margin: 22rpx 51rpx;
			}
			.adimage{
				width: 680rpx;
				height: 258rpx;
			}
		}
	}
	.successsynpopup{
		display: flex;
		justify-content: center;
		align-items: center;
		flex-direction: column;
		.successbtn{
			display: flex;
			align-items: center;
			justify-content: center;
			width: 419rpx;
			height: 88rpx;
			position: relative;
			z-index: 1;
		}
		.successcenter{
			display: flex;
			align-items: center;
			justify-content: center;
			width: 481rpx;
			position: relative;
			flex-direction: column;
			.successtext{
				width: 249rpx;
				text-align: center;
				margin-top: -75rpx;
				line-height: 56rpx;
			}
			.goodsimg{
				position: relative;
				width: 386rpx;
				height: 388rpx;
				display: flex;
				align-items: center;
				justify-content: center;
			}
			.successgoods{
				position: relative;
				width: 211rpx;
				height: 211rpx;
			}
			.bgimg{
				position: absolute;
				width: 100%;
				height: 100%;
				top: 0;
				left: 0;
				z-index: -1;
			}
		}
		.successtop{
			width: 415rpx;
			height: 131rpx;
			display: flex;
			align-items: center;
			justify-content: center;
			position: relative;
		}
	}
	.filesynpopup{
		display: flex;
		flex-direction: column;
		align-items: center;
		width: 690rpx;
		border-radius: 20rpx;
		.filecenter{
			display: flex;
			flex-direction: column;
			align-items: center;
			width: 100%;
			padding: 34rpx 0 36rpx 0;
			box-sizing: border-box;
			.signsuccessimg{
				position: relative;
				width: 173rpx;
				height: 173rpx;
				display: flex;
				align-items: center;
				justify-content: center;
				margin-bottom: 39rpx;
				.signgoods{
					width: 126rpx;
					height: 100%;
					z-index: 1;
				}
			}
			.tiptext{
				width: 508rpx;
				margin-bottom: 41rpx;
				text-align: center;
				line-height: 60rpx;
			}
			.btn{
				width: 209rpx;
				height: 68rpx;
				display: flex;
				align-items: center;
				justify-content: center;
				position: relative;
				padding: 0;
				margin: 0;
				image{
					z-index: 0;
				}
			}
			.btn ::after{
				border: none;
			}
		}
		.filetop{
			display: flex;
			align-items: center;
			justify-content: center;
			position: relative;
			height: 80rpx;
			width: 100%;
			border-radius: 16rpx 16rpx 0px 0px;
			image{
				position: absolute;
				width: 31rpx;
				height: 31rpx;
				right: 24rpx;
			}
		}
	}
	.taskinfo{
		width: 690rpx;
		border-radius: 20rpx;
		padding: 0rpx 26rpx 47rpx 27rpx;
		box-sizing: border-box;
		.item{
			display: flex;
			align-items: center;
			justify-content: space-between;
			width: 100%;
			box-sizing: border-box;
			padding-bottom: 27rpx;
			padding-top: 26rpx;
			.btn{
				display: flex;
				align-items: center;
				justify-content: center;
				width: 139rpx;
				height: 56rpx;
				position: relative;
				margin: 0;
				padding: 0;
				background: rgba(0,0,0,0);
				&::after{
					border: none;
					background: none;
				}
			}
			.iteminfo{
				display: flex;
				align-items: center;
				.itemtext{
					display: flex;
					flex-direction: column;
					.text1{
						margin-bottom: 17rpx;
					}
					.reward{
						display: flex;
						align-items: center;
						image{
							width: 37rpx;
							height: 35rpx;
							margin-right: 10rpx;
						}
					}
				}
				.invitationicon{
					width: 100rpx;
					height: 100rpx;
					margin-right: 24rpx;
				}
			}
		}
	}
	.tasktitle{
		display: flex;
		align-items: center;
		width: 100%;
		margin-bottom: 34rpx;
		.money{
			margin: 0 auto;
			padding-left: 49rpx;
			width: 600rpx;
			.titleitem{
				display: flex;
				align-items: center;
				margin-right: 105rpx;
				.little{
					width: 12rpx;
					height: 12rpx;
					background: #EE0A24;
					border-radius: 50%;
					margin-left: 10rpx;
				}
			}
		}
	}
	.Sign{
		width: 690rpx;
		border-radius: 20rpx;
		box-sizing: border-box;
		padding: 30rpx 0;
		margin-bottom: 56rpx;
		.signother{
			display: flex;
			align-items: center;
			justify-content: space-between;
			padding-left: 31rpx;
			margin-top: 56upx;
			padding-top: 10upx;
			box-sizing: border-box;
			.time{
				display: flex;
				align-items: center;
			}
		}
		.ordinary{
			text-align:center;
			margin-bottom:65rpx;
		}
		.ready-sign{
			width: 260upx;
			height: 80upx;
			display: flex;
			align-items: center;
			justify-content: center;
			position: relative;
			margin: 0 auto;
		}
		.doublesignbtn{
			width: 269rpx;
			height: 88rpx;
			position: relative;
			display: flex;
			align-items: center;
			justify-content: center;
			margin-bottom: 15rpx;
		}
		.signindex{
			width: 100%;
			
			box-sizing: border-box;
			padding: 24rpx 0 39rpx 0;
			margin-bottom: 25rpx;
			.flexaaa{
				display: -webkit-box;
				box-sizing: border-box;
				padding-top: 30rpx;
				.miniItem{
					display: flex;
					flex-direction: column;
					align-items: center;
					box-sizing: border-box;
					position: relative;
					margin-right: 15rpx;
					width: 146rpx;
					height: 231rpx;
					.signready{
						position: absolute;
						z-index: 2;
						width: 30rpx;
						height: 30rpx;
						border-radius: 50%;
						top: 40rpx;
						right: 35rpx;
					}
					.itemtext{
						height: 36rpx;
						width: 128rpx;
						display: flex;
						align-items: center;
						justify-content: center;
						flex-direction: column;
						position: relative;
						z-index: 2;
						font-size: 28rpx;
						margin-bottom: 42rpx;
					}
					.topbg{
						width: 102rpx;
						height: 101rpx;
						position: absolute;
						z-index: 1;
						top: -28rpx;
					}
					.itemicon{
						width: 58rpx;
						height: 58rpx;
						margin-top: -5rpx;
						z-index: 2;
						margin-bottom: 40rpx;
					}
				}
			}
		}
		.titletext{
			margin-bottom:21rpx;
			margin-left:34rpx;
		}
	}
	.user{
		display: flex;
		align-items: center;
		justify-content: space-between;
		width: 690rpx;
		box-sizing: border-box;
		padding: 32rpx 21rpx;
		border-radius: 20rpx;
		margin-bottom: 31rpx;
		position: relative;
		.exchangebtn{
			width: 119rpx;
			height: 56rpx;
			display: flex;
			align-items: center;
			position: relative;
			justify-content: center;
			position: absolute;
			right: 10rpx;
			z-index: 5;
		}
		.userinfo{
			display: flex;
			align-items: center;
			.avatar{
				width: 90rpx;
				height: 90rpx;
				background-color: #FFFFFF;
				border-radius: 10rpx;
				margin-right: 24rpx;
			}
			.userindexa{
				.nameclass{
					margin-bottom: 21rpx;
				}
				.userother{
					display: flex;
					align-items: center;
					width: 480upx;
					flex-wrap: wrap;
					.item{
						display: flex;
						align-items: center;
						position: relative;
						box-sizing: border-box;
						height: 30rpx;
						padding-right: 25rpx;
						margin-left: 22rpx;
						border-radius: 4rpx;
						.item-icon-number{
							white-space:nowrap;
							text-overflow:ellipsis;
							overflow:hidden;
						}
						image{
							width: 36rpx;
							height: 36rpx;
							margin-left: -18rpx;
							margin-right: 5rpx;
						}
					}
				}
			}
			
		}
	}
	.content{
		min-height: 100vh;
		width: 750rpx;
		display: flex;
		flex-direction: column;
		align-items: center;
		box-sizing: border-box;
		padding: 0 30rpx 150rpx 30rpx;
	}
	.footTabList{
		display: flex;
		align-items: center;
		justify-content: space-around;
		position: fixed;
		bottom: 0;
		left: 0;
		width: 750rpx;
		font-size: 24rpx;
		z-index: 999;
		padding-top: 12rpx;
		.listitem{
			display: flex;
			flex-direction: column;
			align-items: center;
			width: 100rpx;
			image{
				width: 42rpx;
				height: 42rpx;
				margin-bottom: 15rpx;
			}
		}
	}
	.topTitle{
		color: #FFFFFF;
		display: flex;
		align-items: center;
		height: 67rpx;
		padding-left: 30rpx;
		justify-content: center;
		position: absolute;
		z-index: 10;
		width: 100%;
	}
</style>
